package ink.yuanchu.picachoframework;

import ink.yuanchu.picachoframework.util.DBUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author ziyuan
 */
@SpringBootApplication
@EnableSwagger2
@EnableScheduling
@MapperScan({"com.gitee.sunchenbin.mybatis.actable.dao.*","ink.yuanchu.picachoframework.dao"} )
@ComponentScan({"com.gitee.sunchenbin.mybatis.actable.manager.*","ink.yuanchu.picachoframework"})
public class PicachoFrameworkApplication {

    public static void main(String[] args) {
        SpringApplication.run(PicachoFrameworkApplication.class, args);
        sqlScriptRun();
    }

    public static void sqlScriptRun() {
        DBUtils dbUtils = DBUtils.getObject();
        boolean init = dbUtils.initializationData();
        if (init == true) {
            dbUtils.executeScript();
        }
    }

}
